package org.newlucene.core.analysis;

import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PluralStemAnalyzer implements Analyzer
{
	private String regexp = "[a-z0-9A-Z]+";
	private Pattern pattern = Pattern.compile(regexp);
	private Matcher matcher = pattern.matcher("");
	private ArrayList<String> list;
	private int index = -1;
	
	public Token next() throws IOException
	{
		index++;
		if (index < list.size())
		{
			return new Token(list.get(index));
		}
		else
		{
			return null;
		}
	}

	public void set(String text)
	{
		matcher.reset(text);
		list = new ArrayList<String>();
		while (matcher.find())
		{
			String word = matcher.group().toLowerCase();
			word = Util.stripEnglishPlural(word);
			list.add(word);
		}
		index = -1;
	}
	
	public static void main(String[] args) throws Exception
	{
		PluralStemAnalyzer analyzer = new PluralStemAnalyzer();
		analyzer.set("6100");
		Token t;
		while ((t = analyzer.next()) != null)
		{
			System.out.println(t);
		}
		
		analyzer.set("6753");
		while ((t = analyzer.next()) != null)
		{
			System.out.println(t);
		}		
	}
}